<div class="row-content am-cf" ng-controller="customerControl">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-body">
                	<!--网格行限制宽度-->
					<div class="am-g">
						<div class="am-u-sm-12">
							<div class="widget-head am-cf">
		                        <div class="widget-title am-fl">客服消息</div>
		                        <div class="am-btn-group am-btn-group-xs am-fr">
	                                <!--<a class="am-btn am-btn-default am-btn-success upload-file" href="javascript:void(0)">-->
	                                <a class="am-btn am-btn-default am-btn-success" href="javascript:void(0)" ng-click="form()">
	                                    <span class="am-icon-plus"></span> 新增
	                                </a>
	                                <div class="uploader-list am-cf"></div>
	                            </div>
		                    </div>
						</div>
					</div>
                    <div class="am-g">
                    	<div class="am-u-sm-12">
							<table class="am-table am-table-hover am-table-centered">
							<!--<table class="am-table am-table-hover">-->
								<thead>
									<tr>
										<th>关键字</th>
										<th>推送类型</th>
										<th width="50%">推送内容</th>
										<th>创建时间</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
									<?php if (!$list->isEmpty()): foreach ($list as $item): ?>
									<tr>
										<td class="am-text-middle">
											<?=$item['keywords']?>
										</td>
										<?php if($item['type'] == 0){ ?>
										<td class="am-text-middle">关键字</td>
										<?php } if($item['type'] == 1){ ?>
										<td class="am-text-middle">进入对话页面</td>
										<?php } if($item['type'] == 2){ ?>
										<td class="am-text-middle">匹配不到关键字</td>
										<?php } ?>
										<td class="am-text-middle"><?=(isset($item['content'])) ? $item['content'] : ''?></td>
										<td class="am-text-middle"><?=date('Y-m-d',$item['date'])?></td>
										<td class="am-text-middle">
											<div class="tpl-table-black-operation">
												<a href="javascript:void(0)" ng-click="form('<?=base64_encode(json_encode($item))?>')">
													<i class="am-icon-pencil"></i> 编辑
												</a>
												<a href="javascript:void(0)" class="item-delete tpl-table-black-operation-del" ng-click="del('<?=$item['id']?>')">
													<i class="am-icon-trash"></i> 删除
												</a>
											</div>
										</td>
									</tr>
									<?php endforeach; else: ?>
									<tr>
	                                    <td colspan="9" class="am-text-center">暂无记录</td>
	                                </tr>
                            		<?php endif; ?>
								</tbody>
							</table>
                    	</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--表单-->
	<div class="ads-form" ng-show="isOpenForm" style="margin-top:35px;">
    	<div class="am-u-sm-10 am-u-sm-centered">
    		<div class="am-panel am-panel-default">
				<!--<div class="am-panel-hd">面板标题</div>-->
				<div class="am-panel-bd">
				    <form class="am-form am-form-horizontal">
						<fieldset>
							<!--<legend>表单标题</legend>-->
							<div class="am-form-group am-form-file">
								<label for="doc-ipt-3" class="am-u-sm-2 am-form-label">关键字</label>
								<div class="am-u-sm-10">
									<input type="text" id="doc-ipt-3" placeholder="关键字" class="href" name="keywords" ng-model="customer.keywords">
								</div>
								<!--图片预览-->
								<div class="img"></div>
							</div>
							<div class="am-form-group">
								<label for="doc-ipt-3" class="am-u-sm-2 am-form-label">推送内容</label>
								<div class="am-u-sm-10">
									<textarea class="" rows="5" id="doc-ta-1" name="content" ng-model="customer.content"></textarea>
								</div>
							</div>
							<div class="am-form-group">
								<label for="doc-ipt-3" class="am-u-sm-2 am-form-label">推送类型</label>
								
								<div class="am-u-sm-10">
									<label class="am-radio-inline">
										<input type="radio"  value="0" name="docInlineRadio" ng-model="customer.type" ng-checked="customer.type"> 关键字
									</label>
									<label class="am-radio-inline">
										<input type="radio" value="1" name="docInlineRadio" ng-model="customer.type" ng-checked="customer.type"> 进入对话页面
									</label>
									<label class="am-radio-inline">
										<input type="radio" value="2" name="docInlineRadio" ng-model="customer.type" ng-checked="customer.type"> 匹配不到关键字
									</label>
								</div>
							</div>
							<div class="am-form-group">
								<div class="am-u-sm-10 am-u-sm-offset-2">
									<button type="submit" class="am-btn am-btn-default" ng-click="save()">保存</button>
								</div>
							</div>
						</fieldset>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- 图片文件列表模板 -->
{{include file="layouts/_template/tpl_file_item" /}}
<!-- 文件库弹窗 -->
{{include file="layouts/_template/file_library" /}}

<script src="https://cdn.bootcss.com/angular.js/1.7.9/angular.min.js"></script>
<script src="assets/common/plugins/layer/layer.js"></script>
<script src="assets/common/js/ddsort.js"></script>
<!--[if IE]>
<script src="https://www.zhangxinxu.com/wordpress/2018/08/js-base64-atob-btoa-encode-decode/base64-polyfill.js"></script>
<![endif]-->

<script>
	var app = angular.module('app', []);
	app.controller('customerControl', ['$scope','$http',function($scope,$http) {
		$scope.isOpenForm = false;
		$scope.customer = {type:'0'}; // 要保存的数据
		// 显示表单
		$scope.form = function(item=null){
			$scope.customer = {type:'0'};
			$scope.isOpenForm = true;
			layer.open({
				type: 1,
				skin: 'layui-layer-rim', //加上边框
				area: ['800px', '400px'], //宽高
				content: $('.ads-form')
			});
			if(item!=null){
				item = JSON.parse(window.atob(item));
				$scope.customer = item;
				$scope.customer.type = item.type+'';
				// console.log($scope.customer)
			}
		}
		
		// 保存
		$scope.save = function(){
			// console.log(this.customer);
			// return false;
			if(!this.customer.keywords){
				alert('请输入关键字');
				return false;
			}
			if(!this.customer.content){
				alert('请输入推送内容');
				return false;
			}
			$http.post('https://kb.yinhua95.com/index.php?s=/store/customer/save',$scope.customer).then(res=>{
				console.log(res);
				if(res.data == 0 || res.data == 1){
					window.location.reload()
					return false;
				}
				alert('保存失败');
			});
		}
		
		// 删除
		$scope.del = function(id){
			if(confirm('确定要删除吗？')){
				$http.post('https://kb.yinhua95.com/index.php?s=/store/customer/del',{id:id}).then(res=>{
					if(res.data == 1){
						alert('删除成功');
						window.location.reload();
						return false;
					}
					if(res.data == 0){
						alert('当前数据已删除');
						window.location.reload();
						return false;
					}
					alert('删除失败');
				});	
			}
		}
	}]);
</script>

